package main;

import java.awt.AWTException;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.alibaba.fastjson.JSON;

import common.AntiCrack;
import dataType.FitLogic;
import dataType.Point;
import dataType.Storage;
import dataType.WindowsClient;
import form.CommonForm;
import form.WindowsMsg;
import function.GetFouce;
import function.IO;

public class Frame implements ActionListener {
	private Frame self;

	public static Storage storage = new Storage();
	public static FitLogic currentLogic = new FitLogic();
	
	public void getFrame(Frame self) {
		this.self = self;
	}

	
	JFrame jf;
	CommonForm cf;
	GetFouce gf;
	Robot rb;
	FrameSet fs;
	WindowsMsg win1;
	WindowsMsg win2;
	WindowsMsg win3;
	WindowsMsg win4;
	WindowsMsg win5;
	JButton jbtab1;
	JButton jbtab2;
	JButton jbtab3;
	JButton jbtab4;
	JButton currentTab;
	final JTextField jtf1 = new JTextField();
	final JTextField jtf2 = new JTextField();
	final JTextField jtf11 = new JTextField();
	final JTextField jtf12 = new JTextField();
	final JTextField jtf21 = new JTextField();
	final JTextField jtf22 = new JTextField();
	final JTextField jtf31 = new JTextField();
	final JTextField jtf32 = new JTextField();
	final JTextField jtf41 = new JTextField();
	final JTextField jtf42 = new JTextField();
	final JTextField jtf51 = new JTextField();
	final JTextField jtf52 = new JTextField();
	final JTextField jtf13 = new JTextField();
	final JTextField jtf14 = new JTextField();
	final JTextField jtf23 = new JTextField();
	final JTextField jtf24 = new JTextField();
	final JTextField jtf33 = new JTextField();
	final JTextField jtf34 = new JTextField();
	final JTextField jtf43 = new JTextField();
	final JTextField jtf44 = new JTextField();
	final JTextField jtf53 = new JTextField();
	final JTextField jtf54 = new JTextField();
	final JPanel jp12 = new JPanel();
	final JPanel jp22 = new JPanel();
	final JPanel jp32 = new JPanel();
	final JPanel jp42 = new JPanel();
	final JPanel jp52 = new JPanel();

	public Frame(String title) {
		try {
			cf = new CommonForm();
			jf = new JFrame("有效期至" + title);
			win1 = new WindowsMsg();
			win2 = new WindowsMsg();
			win3 = new WindowsMsg();
			win4 = new WindowsMsg();
			win5 = new WindowsMsg();
			gf = new GetFouce();
			fs = new FrameSet(cf);
			try {
				rb = new Robot();
			} catch (AWTException e) {
				JOptionPane.showMessageDialog(null, "！！！没有足够的权限！！！");
				System.exit(0);
			}
			jtf11.setOpaque(true);
			jtf12.setOpaque(true);
			jtf21.setOpaque(true);
			jtf22.setOpaque(true);
			jtf31.setOpaque(true);
			jtf32.setOpaque(true);
			jtf41.setOpaque(true);
			jtf42.setOpaque(true);
			jtf51.setOpaque(true);
			jtf52.setOpaque(true);
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	public void doFrame(Point Locate, Point Size) {
		jf.setLayout(new BorderLayout());
		jf.setBounds(Locate.X, Locate.Y, Size.X, Size.Y);
		jf.setResizable(false);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public void doTopPanel() {
		try {
			final JPanel jp = new JPanel();
			final JPanel jp0 = new JPanel();
			final JPanel jp1 = new JPanel();
			jp1.setLayout(new GridLayout(1,4));
			final JPanel jpNorth = new JPanel();
			JLabel jl0 = new JLabel("角色名称");
			jl0.setForeground(Color.WHITE);
			GridLayout gl = new GridLayout(1, 4);
			JLabel jl1 = new JLabel("大区", JLabel.RIGHT);
			JLabel jl2 = new JLabel("服务器", JLabel.RIGHT);
			jtf1.addKeyListener(new KeyListener() {
				public void keyTyped(KeyEvent e) {
				}

				public void keyReleased(KeyEvent e) {
				}

				public void keyPressed(KeyEvent e) {
					if (e.getKeyChar() == '\n') {
						jtf2.requestFocus();
					}
				}
			});
			jtf2.addKeyListener(new KeyListener() {
				public void keyTyped(KeyEvent e) {
				}

				public void keyReleased(KeyEvent e) {
				}

				public void keyPressed(KeyEvent e) {
					if (e.getKeyChar() == '\n' && !jtf1.getText().equals("")
							&& !jtf2.getText().equals("")) {
						cf.setArea(jtf1.getText().replaceAll(" ", ""));
						cf.setServer(jtf2.getText().replaceAll(" ", ""));
						jf.setTitle(cf.getArea() + "[" + cf.getServer() + "]");
						jp.setVisible(false);
						jf.add(jp0, BorderLayout.NORTH);
						jp0.setVisible(true);
					}
				}
			});
				
			jp0.setLayout(gl);
			jp0.setBackground(Color.BLUE);
			jp.add(jl1);
			jp.add(jtf1);
			jp.add(jl2);
			jp.add(jtf2);
			gl.setHgap(2);
			gl.setVgap(2);
			jp.setLayout(gl);
			jp0.add(jl0);
			jl0 = new JLabel("角色ID");
			jl0.setForeground(Color.WHITE);
			jp0.add(jl0);
			jl0 = new JLabel("人物攻击");
			jl0.setForeground(Color.WHITE);
			jp0.add(jl0);
			jl0 = new JLabel("召唤兽攻击");
			jl0.setForeground(Color.WHITE);
			jp0.add(jl0);
			jp0.setVisible(false);
			jf.add(jp, BorderLayout.NORTH);

			jbtab1 = new JButton("方案1");
			jbtab1.setActionCommand("tab1");
			jbtab2 = new JButton("方案2");
			jbtab2.setActionCommand("tab2");
			jbtab3 = new JButton("方案3");
			jbtab3.setActionCommand("tab3");
			jbtab4 = new JButton("方案4");
			jbtab4.setActionCommand("tab4");
			ActionListener al = new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					refreashTab();
					String command = e.getActionCommand();
					if("tab1".equals(command)) {
						Frame.currentLogic = Frame.storage.getLogicList().get(0);
					}else if("tab2".equals(command)) {
						Frame.currentLogic = Frame.storage.getLogicList().get(1);
						
					}else if("tab3".equals(command)) {
						Frame.currentLogic = Frame.storage.getLogicList().get(2);
						
					}else if("tab4".equals(command)) {
						Frame.currentLogic = Frame.storage.getLogicList().get(3);
						
					}
					currentTab = (JButton)e.getSource();
					effectByCurrentLogic();
				}
			};
			currentTab = jbtab1;
			jbtab1.addActionListener(al);
			jbtab2.addActionListener(al);
			jbtab3.addActionListener(al);
			jbtab4.addActionListener(al);
			jp1.add(jbtab1);
			jp1.add(jbtab2);
			jp1.add(jbtab3);
			jp1.add(jbtab4);
			cf.setArea(jtf1.getText().replaceAll(" ", ""));
			cf.setServer(jtf2.getText().replaceAll(" ", ""));
			jf.setTitle(cf.getArea() + "[" + cf.getServer() + "]");
			jp.setVisible(false);
//			jf.add(jp0, BorderLayout.NORTH);
			jpNorth.setLayout(new GridLayout(2,1));
			jpNorth.add(jp1);
			jpNorth.add(jp0);
			jf.add(jpNorth, BorderLayout.NORTH);
			jp0.setVisible(true);
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	public void doCenterPanel() {
		try {
			Insets margin = new Insets(0, 0, 0, 0);
			JPanel jp = new JPanel();
			JPanel jp1 = new JPanel();
			JPanel jp2 = new JPanel();
			JPanel jp3 = new JPanel();
			JPanel jp4 = new JPanel();
			JPanel jp5 = new JPanel();
			jp.setLayout(new GridLayout(5, 1));
			JButton jb11 = new JButton("清屏");
			JButton jb12 = new JButton("切换");
			JButton jb21 = new JButton("清屏");
			JButton jb22 = new JButton("切换");
			JButton jb31 = new JButton("清屏");
			JButton jb32 = new JButton("切换");
			JButton jb41 = new JButton("清屏");
			JButton jb42 = new JButton("切换");
			JButton jb51 = new JButton("清屏");
			JButton jb52 = new JButton("切换");
			JButton jb13 = new JButton("例外攻击");
			jb13.setMargin(margin);
			JButton jb14 = new JButton("攻击");
			jb14.setBackground(Color.RED);
			JButton jb23 = new JButton("例外攻击");
			jb23.setMargin(margin);
			JButton jb24 = new JButton("攻击");
			jb24.setBackground(Color.RED);
			JButton jb33 = new JButton("例外攻击");
			jb33.setMargin(margin);
			JButton jb34 = new JButton("攻击");
			jb34.setBackground(Color.RED);
			JButton jb43 = new JButton("例外攻击");
			jb43.setMargin(margin);
			JButton jb44 = new JButton("攻击");
			jb44.setBackground(Color.RED);
			JButton jb53 = new JButton("例外攻击");
			jb53.setMargin(margin);
			JButton jb54 = new JButton("攻击");
			jb54.setBackground(Color.RED);
			GridLayout gl = new GridLayout(1, 4);
			
			jtf11.addMouseListener(new MouseListener() {
				public void mouseReleased(MouseEvent e) {
				}
				public void mousePressed(MouseEvent e) {
				}
				public void mouseExited(MouseEvent e) {
				}
				public void mouseEntered(MouseEvent e) {
				}
				public void mouseClicked(MouseEvent e) {
					if(!jtf11.isEditable()){
						return;
					}
					List<WindowsClient> clients = GetFouce.mhClients();
					Object[] obj = new Object[clients.size()];
					for(int i =0 ; i < clients.size();i++){
						obj[i] = clients.get(i).getShowName();
					}
					String option = (String) JOptionPane.showInputDialog(null, "请选择绑定的客户端\n","选择绑定",JOptionPane.PLAIN_MESSAGE,null,obj,"");
					if(option == null || option == ""){
						return;
					}
					for(WindowsClient client : clients){
						if(client.getShowName().equals(option)){
							win1.setHwnd(client.getHwnd());
							jtf11.setText(client.getShowName());
							jtf12.setText(client.getId());
							jtf11.setBackground(Color.GREEN);
							jtf12.setBackground(Color.GREEN);
							jtf11.setEditable(false);
							jtf12.setEditable(false);
							break;
						}
					}
				}
			});

			jtf21.addMouseListener(new MouseListener() {
				public void mouseReleased(MouseEvent e) {
				}
				public void mousePressed(MouseEvent e) {
				}
				public void mouseExited(MouseEvent e) {
				}
				public void mouseEntered(MouseEvent e) {
				}
				public void mouseClicked(MouseEvent e) {
					if(!jtf21.isEditable()){
						return;
					}
					List<WindowsClient> clients = GetFouce.mhClients();
					Object[] obj = new Object[clients.size()];
					for(int i =0 ; i < clients.size();i++){
						obj[i] = clients.get(i).getShowName();
					}
					String option = (String) JOptionPane.showInputDialog(null, "请选择绑定的客户端\n","选择绑定",JOptionPane.PLAIN_MESSAGE,null,obj,"");
					if(option == null || option == ""){
						return;
					}
					for(WindowsClient client : clients){
						if(client.getShowName().equals(option)){
							win2.setHwnd(client.getHwnd());
							jtf21.setText(client.getShowName());
							jtf22.setText(client.getId());
							jtf21.setBackground(Color.GREEN);
							jtf22.setBackground(Color.GREEN);
							jtf21.setEditable(false);
							jtf22.setEditable(false);
							break;
						}
					}
				}
			});

			jtf31.addMouseListener(new MouseListener() {
				public void mouseReleased(MouseEvent e) {
				}
				public void mousePressed(MouseEvent e) {
				}
				public void mouseExited(MouseEvent e) {
				}
				public void mouseEntered(MouseEvent e) {
				}
				public void mouseClicked(MouseEvent e) {
					if(!jtf31.isEditable()){
						return;
					}
					List<WindowsClient> clients = GetFouce.mhClients();
					Object[] obj = new Object[clients.size()];
					for(int i =0 ; i < clients.size();i++){
						obj[i] = clients.get(i).getShowName();
					}
					String option = (String) JOptionPane.showInputDialog(null, "请选择绑定的客户端\n","选择绑定",JOptionPane.PLAIN_MESSAGE,null,obj,"");
					if(option == null || option == ""){
						return;
					}
					for(WindowsClient client : clients){
						if(client.getShowName().equals(option)){
							win3.setHwnd(client.getHwnd());
							jtf31.setText(client.getShowName());
							jtf32.setText(client.getId());
							jtf31.setBackground(Color.GREEN);
							jtf32.setBackground(Color.GREEN);
							jtf31.setEditable(false);
							jtf32.setEditable(false);
							break;
						}
					}
				}
			});

			jtf41.addMouseListener(new MouseListener() {
				public void mouseReleased(MouseEvent e) {
				}
				public void mousePressed(MouseEvent e) {
				}
				public void mouseExited(MouseEvent e) {
				}
				public void mouseEntered(MouseEvent e) {
				}
				public void mouseClicked(MouseEvent e) {
					if(!jtf41.isEditable()){
						return;
					}
					List<WindowsClient> clients = GetFouce.mhClients();
					Object[] obj = new Object[clients.size()];
					for(int i =0 ; i < clients.size();i++){
						obj[i] = clients.get(i).getShowName();
					}
					String option = (String) JOptionPane.showInputDialog(null, "请选择绑定的客户端\n","选择绑定",JOptionPane.PLAIN_MESSAGE,null,obj,"");
					if(option == null || option == ""){
						return;
					}
					for(WindowsClient client : clients){
						if(client.getShowName().equals(option)){
							win4.setHwnd(client.getHwnd());
							jtf41.setText(client.getShowName());
							jtf42.setText(client.getId());
							jtf41.setBackground(Color.GREEN);
							jtf42.setBackground(Color.GREEN);
							jtf41.setEditable(false);
							jtf42.setEditable(false);
							break;
						}
					}
				}
			});

			jtf51.addMouseListener(new MouseListener() {
				public void mouseReleased(MouseEvent e) {
				}
				public void mousePressed(MouseEvent e) {
				}
				public void mouseExited(MouseEvent e) {
				}
				public void mouseEntered(MouseEvent e) {
				}
				public void mouseClicked(MouseEvent e) {
					if(!jtf51.isEditable()){
						return;
					}
					List<WindowsClient> clients = GetFouce.mhClients();
					Object[] obj = new Object[clients.size()];
					for(int i =0 ; i < clients.size();i++){
						obj[i] = clients.get(i).getShowName();
					}
					String option = (String) JOptionPane.showInputDialog(null, "请选择绑定的客户端\n","选择绑定",JOptionPane.PLAIN_MESSAGE,null,obj,"");
					if(option == null || option == ""){
						return;
					}
					for(WindowsClient client : clients){
						if(client.getShowName().equals(option)){
							win5.setHwnd(client.getHwnd());
							jtf51.setText(client.getShowName());
							jtf52.setText(client.getId());
							jtf51.setBackground(Color.GREEN);
							jtf52.setBackground(Color.GREEN);
							jtf51.setEditable(false);
							jtf52.setEditable(false);
							break;
						}
					}
				}
			});
			KeyListener kl = new KeyListener() {
				
				@Override
				public void keyTyped(KeyEvent e) {
					((JTextField) e.getSource()).setText("");
				}
				@Override
				public void keyReleased(KeyEvent e) {
				}
				@Override
				public void keyPressed(KeyEvent e) {
				}
			};
			jtf13.addKeyListener(kl);
			jtf14.addKeyListener(kl);
			jtf23.addKeyListener(kl);
			jtf24.addKeyListener(kl);
			jtf33.addKeyListener(kl);
			jtf34.addKeyListener(kl);
			jtf43.addKeyListener(kl);
			jtf44.addKeyListener(kl);
			jtf53.addKeyListener(kl);
			jtf54.addKeyListener(kl);
			
			jb11.addActionListener(this);
			jb11.setActionCommand("btn12");
			jb12.addActionListener(this);
			jb12.setActionCommand("btn11");
			jb21.addActionListener(this);
			jb21.setActionCommand("btn22");
			jb22.addActionListener(this);
			jb22.setActionCommand("btn21");
			jb31.addActionListener(this);
			jb31.setActionCommand("btn32");
			jb32.addActionListener(this);
			jb32.setActionCommand("btn31");
			jb41.addActionListener(this);
			jb41.setActionCommand("btn42");
			jb42.addActionListener(this);
			jb42.setActionCommand("btn41");
			jb51.addActionListener(this);
			jb51.setActionCommand("btn52");
			jb52.addActionListener(this);
			jb52.setActionCommand("btn51");
			jb13.addActionListener(this);
			jb13.setActionCommand("btn13");
			jb14.addActionListener(this);
			jb14.setActionCommand("btn14");
			jb23.addActionListener(this);
			jb23.setActionCommand("btn23");
			jb24.addActionListener(this);
			jb24.setActionCommand("btn24");
			jb33.addActionListener(this);
			jb33.setActionCommand("btn33");
			jb34.addActionListener(this);
			jb34.setActionCommand("btn34");
			jb43.addActionListener(this);
			jb43.setActionCommand("btn43");
			jb44.addActionListener(this);
			jb44.setActionCommand("btn44");
			jb53.addActionListener(this);
			jb53.setActionCommand("btn53");
			jb54.addActionListener(this);
			jb54.setActionCommand("btn54");

			gl.setHgap(3);
			gl.setVgap(3);
			jp1.setLayout(gl);
			jp2.setLayout(gl);
			jp3.setLayout(gl);
			jp4.setLayout(gl);
			jp5.setLayout(gl);
			jp1.add(jtf11);
			jp1.add(jtf12);
			jp1.add(jtf13);
			jp1.add(jtf14);
//			jp1.add(jb13);
//			jp1.add(jb14);
//			jp1.add(jb11);
//			jp1.add(jb12);
			jp2.add(jtf21);
			jp2.add(jtf22);
			jp2.add(jtf23);
			jp2.add(jtf24);
//			jp2.add(jb23);
//			jp2.add(jb24);
//			jp2.add(jb21);
//			jp2.add(jb22);

			jp3.add(jtf31);
			jp3.add(jtf32);
			jp3.add(jtf33);
			jp3.add(jtf34);
//			jp3.add(jb33);
//			jp3.add(jb34);
//			jp3.add(jb31);
//			jp3.add(jb32);

			jp4.add(jtf41);
			jp4.add(jtf42);
			jp4.add(jtf43);
			jp4.add(jtf44);
//			jp4.add(jb43);
//			jp4.add(jb44);
//			jp4.add(jb41);
//			jp4.add(jb42);

			jp5.add(jtf51);
			jp5.add(jtf52);
			jp5.add(jtf53);
			jp5.add(jtf54);
//			jp5.add(jb53);
//			jp5.add(jb54);
//			jp5.add(jb51);
//			jp5.add(jb52);

			jp.add(jp1);
			jp.add(jp2);
			jp.add(jp3);
			jp.add(jp4);
			jp.add(jp5);
			jf.add(jp, BorderLayout.CENTER);
			jf.setVisible(true);
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	public void doBottomPanel() {
		try {
			JPanel jpsouth = new JPanel();
			jpsouth.setLayout(new GridLayout(2,1));
			JPanel jp = new JPanel();
			JButton jb = new JButton("全体攻击");
			jb.setActionCommand("all");
			JButton jbb = new JButton("全体防御");
			jbb.setActionCommand("allDefense");
			JButton jbsv = new JButton("设置 & 功能");
			jbsv.setMargin(new Insets(0, 0, 0, 0));
			jbsv.setActionCommand("save");
			jb.addActionListener(this);
			jbb.addActionListener(this);
			jbsv.addActionListener(this);
			//jp.setLayout(new GridLayout(2, 3));
			jp.setLayout(new GridLayout(1, 3));
			JButton jbxq = new JButton("解锁");
			jbxq.setActionCommand("unlock");
			jbxq.addActionListener(this);
//			JButton jbxq = new JButton("人打宠防");
//			jbxq.setActionCommand("att&def");
//			jbxq.addActionListener(this);
//			JButton jbxq = new JButton("续期");
//			jbxq.setActionCommand("BuyCard");
//			jbxq.addActionListener(this);
			JButton jbchange1 = new JButton("全体清屏");
			jbchange1.setActionCommand("cleanall");
			jbchange1.addActionListener(this);
			JButton jbchange2 = new JButton("顺序延迟切换");
			jbchange2.setMargin(new Insets(0, 0, 0, 0));
			jbchange2.setActionCommand("changeall");
			jbchange2.addActionListener(this);
			jp.add(jbxq);
//			jp.add(jbchange2);
//			jp.add(jbchange1);
			jp.add(jbb);
			jp.add(jbsv);
//			jp.add(jb);
//			jf.add(jp, BorderLayout.SOUTH);
			
			JPanel jp2 = new JPanel();
			jp2.setLayout(new GridLayout(1,4));

			JButton jbexe1 = new JButton("执行1");
			jbexe1.setActionCommand("tab1");
			jbexe1.addActionListener(this);
			JButton jbexe2 = new JButton("执行2");
			jbexe2.setActionCommand("tab2");
			jbexe2.addActionListener(this);
			JButton jbexe3 = new JButton("执行3");
			jbexe3.setActionCommand("tab3");
			jbexe3.addActionListener(this);
			JButton jbexe4 = new JButton("执行4");
			jbexe4.setActionCommand("tab4");
			jbexe4.addActionListener(this);
			jp2.add(jbexe1);
			jp2.add(jbexe2);
			jp2.add(jbexe3);
			jp2.add(jbexe4);
			jpsouth.add(jp);
			jpsouth.add(jp2);
			jf.add(jpsouth, BorderLayout.SOUTH);
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	public void actionPerformed(ActionEvent e) {
		try {
			if (e.getActionCommand().equals("all")) {
				gf.getForce(cf, win1);
				pressButton(1);
				gf.getForce(cf, win2);
				pressButton(2);
				gf.getForce(cf, win3);
				pressButton(3);
				gf.getForce(cf, win4);
				pressButton(4);
				gf.getForce(cf, win5);
				pressButton(5);
			} else if ((e.getActionCommand().equals("unlock"))){
				jtf11.setEditable(true);
				jtf12.setEditable(true);
				jtf21.setEditable(true);
				jtf22.setEditable(true);
				jtf31.setEditable(true);
				jtf32.setEditable(true);
				jtf41.setEditable(true);
				jtf42.setEditable(true);
				jtf51.setEditable(true);
				jtf52.setEditable(true);
			}else if (e.getActionCommand().startsWith("tab")) {
				int tabNO = Integer.valueOf(e.getActionCommand().replaceAll("tab", "")) -1;
				gf.getForce(cf, win1);
				pressKey(getKeyCode(storage.getLogicList().get(tabNO).getRole1Logic()),getKeyCode(storage.getLogicList().get(tabNO).getDog1Logic()));
				gf.getForce(cf, win2);
				pressKey(getKeyCode(storage.getLogicList().get(tabNO).getRole2Logic()),getKeyCode(storage.getLogicList().get(tabNO).getDog2Logic()));
				gf.getForce(cf, win3);
				pressKey(getKeyCode(storage.getLogicList().get(tabNO).getRole3Logic()),getKeyCode(storage.getLogicList().get(tabNO).getDog3Logic()));
				gf.getForce(cf, win4);
				pressKey(getKeyCode(storage.getLogicList().get(tabNO).getRole4Logic()),getKeyCode(storage.getLogicList().get(tabNO).getDog4Logic()));
				gf.getForce(cf, win5);
				pressKey(getKeyCode(storage.getLogicList().get(tabNO).getRole5Logic()),getKeyCode(storage.getLogicList().get(tabNO).getDog5Logic()));
			}else if (e.getActionCommand().equals("att&def")) {
					gf.getForce(cf, win1);
					pressKey(getKey(1, 1),KeyEvent.VK_D);
					gf.getForce(cf, win2);
					pressKey(getKey(2, 1),KeyEvent.VK_D);
					gf.getForce(cf, win3);
					pressKey(getKey(3, 1),KeyEvent.VK_D);
					gf.getForce(cf, win4);
					pressKey(getKey(4, 1),KeyEvent.VK_D);
					gf.getForce(cf, win5);
					pressKey(getKey(5, 1),KeyEvent.VK_D);
			} else if (e.getActionCommand().equals("allDefense")) {
				allDefense(6);
			} else if (e.getActionCommand().equals("btn11")) {
				gf.getForce(cf, win1);
			} else if (e.getActionCommand().equals("btn21")) {
				gf.getForce(cf, win2);
			} else if (e.getActionCommand().equals("btn31")) {
				gf.getForce(cf, win3);
			} else if (e.getActionCommand().equals("btn41")) {
				gf.getForce(cf, win4);
			} else if (e.getActionCommand().equals("btn51")) {
				gf.getForce(cf, win5);
			} else if (e.getActionCommand().equals("btn12")) {
				gf.getForce(cf, win1);
				CreanWindow();
			} else if (e.getActionCommand().equals("btn22")) {
				gf.getForce(cf, win2);
				CreanWindow();
			} else if (e.getActionCommand().equals("btn32")) {
				gf.getForce(cf, win3);
				CreanWindow();
			} else if (e.getActionCommand().equals("btn42")) {
				gf.getForce(cf, win4);
				CreanWindow();
			} else if (e.getActionCommand().equals("btn52")) {
				gf.getForce(cf, win5);
				CreanWindow();
			} else if (e.getActionCommand().equals("btn13")) {
				gf.getForce(cf, win1);
				allDefense(1);
			} else if (e.getActionCommand().equals("btn14")) {
				gf.getForce(cf, win1);
				pressButton(1);
			} else if (e.getActionCommand().equals("btn23")) {
				gf.getForce(cf, win2);
				allDefense(2);
			} else if (e.getActionCommand().equals("btn24")) {
				gf.getForce(cf, win2);
				pressButton(2);
			} else if (e.getActionCommand().equals("btn33")) {
				gf.getForce(cf, win3);
				allDefense(3);
			} else if (e.getActionCommand().equals("btn34")) {
				gf.getForce(cf, win3);
				pressButton(3);
			} else if (e.getActionCommand().equals("btn43")) {
				gf.getForce(cf, win4);
				allDefense(4);
			} else if (e.getActionCommand().equals("btn44")) {
				gf.getForce(cf, win4);
				pressButton(4);
			} else if (e.getActionCommand().equals("btn53")) {
				gf.getForce(cf, win5);
				allDefense(5);
			} else if (e.getActionCommand().equals("btn54")) {
				gf.getForce(cf, win5);
				pressButton(5);
			} else if (e.getActionCommand().equals("cleanall")) {
				changeall(0);
			} else if (e.getActionCommand().equals("changeall")) {
				changeall(1);
			} else if (e.getActionCommand().equals("save")) {
				SetInstall("设置 & 功能");
			} else if (e.getActionCommand().equals("BuyCard")){
				doBuyCard();
			}
		} catch (Exception e1) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e1);
			throw illegalargumentexception;
		}
	}

	private void doBuyCard() {
		Activation act = new Activation();
		String msg = act.getB();
		doActivate da = new doActivate(2,msg);
	}

	private void changeall(int i) {
		try {
			try {
				gf.getForce(cf, win1);
				if (i == 0) {
					CreanWindow();
				} else
					Thread.sleep(cf.getTime3() * 1000);
				gf.getForce(cf, win2);
				if (i == 0) {
					CreanWindow();
				} else
					Thread.sleep(cf.getTime3() * 1000);
				gf.getForce(cf, win3);
				if (i == 0) {
					CreanWindow();
				} else
					Thread.sleep(cf.getTime3() * 1000);
				gf.getForce(cf, win4);
				if (i == 0) {
					CreanWindow();
				} else
					Thread.sleep(cf.getTime3() * 1000);
				gf.getForce(cf, win5);
				if (i == 0) {
					CreanWindow();
				}
			} catch (Exception e) {
				JOptionPane.showMessageDialog(null, "未知错误！");
			}
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	public void allDefense(int winNO) {
		try {
			int KeyCode1 = 68;
			int KeyCode2 = 68;
			if (winNO > 0 && winNO < 6) {

				switch (winNO) {
				case 1:
					gf.getForce(cf, win1);
					break;
				case 2:
					gf.getForce(cf, win2);
					break;
				case 3:
					gf.getForce(cf, win3);
					break;
				case 4:
					gf.getForce(cf, win4);
					break;
				case 5:
					gf.getForce(cf, win5);
					break;
				}
				pressButton(winNO);
			}
			gf.getForce(cf, win1);
			pressKey(KeyCode1, KeyCode2);

			gf.getForce(cf, win2);
			pressKey(KeyCode1, KeyCode2);

			gf.getForce(cf, win3);
			pressKey(KeyCode1, KeyCode2);

			gf.getForce(cf, win4);
			pressKey(KeyCode1, KeyCode2);

			gf.getForce(cf, win5);
			pressKey(KeyCode1, KeyCode2);
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	/**
	 * 恢复功能暂时有压力 private void doHuifu(WindowsMsg win) { try { Thread.sleep(50);
	 * rb.mouseMove(win.getXBlood().X, win.getXBlood().Y); Thread.sleep(50);
	 * rb.mousePress(MouseEvent.BUTTON1_MASK); Thread.sleep(50);
	 * rb.mouseRelease(MouseEvent.BUTTON1_MASK); Thread.sleep(50);
	 * rb.mouseMove(win.getXMagic().X, win.getXMagic().Y); Thread.sleep(50);
	 * rb.mousePress(MouseEvent.BUTTON1_MASK); Thread.sleep(50);
	 * rb.mouseRelease(MouseEvent.BUTTON1_MASK); Thread.sleep(50);
	 * rb.mouseMove(win.getMain().X, win.getMain().Y); Thread.sleep(50);
	 * rb.mousePress(MouseEvent.BUTTON1_MASK); Thread.sleep(50);
	 * rb.mouseRelease(MouseEvent.BUTTON1_MASK); Thread.sleep(50); } catch
	 * (Exception e) { JOptionPane.showMessageDialog(null, "未设置"); } }
	 **/
	private void SetInstall(String label) {
		try {
			fs.show(self, label);
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	private void CreanWindow() {
		try {
			try {
				try {
					Thread.sleep(cf.getTime1());
				} catch (Exception e) {
					Thread.sleep(50);
				}
				rb.keyPress(KeyEvent.VK_F9);
				rb.keyRelease(KeyEvent.VK_F9);
				try {
					Thread.sleep(cf.getTime2());
				} catch (Exception e) {
					Thread.sleep(10);
				}
				rb.keyPress(KeyEvent.VK_ALT);
				rb.keyPress(KeyEvent.VK_H);
				rb.keyRelease(KeyEvent.VK_H);
				rb.keyRelease(KeyEvent.VK_ALT);
				try {
					Thread.sleep(cf.getTime1());
				} catch (Exception e) {
					Thread.sleep(50);
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	public void pressButton(int winNo) {
		try {
			int KeyCode1 = getKey(winNo, 1);
			int KeyCode2 = getKey(winNo, 2);

			if (KeyCode1 != -1 && KeyCode2 != -1)
				pressKey(KeyCode1, KeyCode2);
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	private void pressKey(int keyCode1, int keyCode2) {
		try {
			int time1;
			int time2;
			try {
				time1 = cf.getTime1();
			} catch (Exception e) {
				time1 = 50;
			}
			try {
				time2 = cf.getTime2();
			} catch (Exception e) {
				time2 = 10;
			}
			try {
				Thread.sleep(time1);
				rb.keyPress(KeyEvent.VK_ALT);
				rb.keyPress(keyCode1);
				rb.keyRelease(keyCode1);
				Thread.sleep(time2);
				rb.keyPress(keyCode2);
				rb.keyRelease(keyCode2);
				rb.keyRelease(KeyEvent.VK_ALT);
				Thread.sleep(time1);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} catch (Exception e) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(
					e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	private int getKey(int winNo, int i) {
		try{
		try {
			switch (winNo) {
			case 1:
				if (i == 1)
					return getKeyCode(jtf13.getText());
				return getKeyCode(jtf14.getText());
			case 2:
				if (i == 1)
					return getKeyCode(jtf23.getText());
				return getKeyCode(jtf24.getText());
			case 3:
				if (i == 1)
					return getKeyCode(jtf33.getText());
				return getKeyCode(jtf34.getText());
			case 4:
				if (i == 1)
					return getKeyCode(jtf43.getText());
				return getKeyCode(jtf44.getText());
			case 5:
				if (i == 1)
					return getKeyCode(jtf53.getText());
				return getKeyCode(jtf54.getText());
			}
		} catch (Exception e) {
			return -1;
		}
		return -1;
		}catch(Exception e){
			IllegalArgumentException illegalargumentexception =new IllegalArgumentException(e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	private int getKeyCode(String key) {
		try{
		String Code = key.replace(" ", "").toLowerCase();
		if ("a".equals(Code)) {
			return KeyEvent.VK_A;
		} else if ("q".equals(Code)) {
			return KeyEvent.VK_Q;
		} else if ("d".equals(Code)) {
			return KeyEvent.VK_D;
		} else if ("r".equals(Code)) {
			return KeyEvent.VK_R;
		}
		return -1;
		}catch(Exception e){
			IllegalArgumentException illegalargumentexception =new IllegalArgumentException(e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}

	/**
	 * BB回复功能有待开发 private void doResume(int type) { switch (type) { case 11:
	 * doResumeEvent(win1.getBBlood()); break; case 12:
	 * 
	 * break; case 13:
	 * 
	 * break; case 21: doResumeEvent(win2.getBBlood()); break; case 22:
	 * 
	 * break; case 23:
	 * 
	 * break; case 31: doResumeEvent(win3.getBBlood()); break; case 32:
	 * 
	 * break; case 33:
	 * 
	 * break; case 41: doResumeEvent(win4.getBBlood()); break; case 42:
	 * 
	 * break; case 43:
	 * 
	 * break; case 51: doResumeEvent(win5.getBBlood()); break; case 52:
	 * 
	 * break; case 53:
	 * 
	 * break;
	 * 
	 * case 99: doResumeEvent(win1.getBBlood());
	 * doResumeEvent(win2.getBBlood()); doResumeEvent(win3.getBBlood());
	 * doResumeEvent(win4.getBBlood()); doResumeEvent(win5.getBBlood()); break;
	 * } }
	 * 
	 * private void doResumeEvent(Point p) { try { Thread.sleep(50);
	 * rb.mouseMove(p.X, p.Y); Thread.sleep(5);
	 * rb.mousePress(MouseEvent.BUTTON3_MASK); Thread.sleep(50);
	 * rb.mouseRelease(MouseEvent.BUTTON3_MASK); Thread.sleep(20); } catch
	 * (Exception e) { } }
	 **/
//	public void read() {
//		try{
//		IO io = new IO();
//		String str = io.read();
//		if (null != str) {
//			String msg[] = str.replace("null", "").split("'");
//			jtf1.setText(msg[0]);
//			jtf2.setText(msg[1]);
//			jtf11.setText(msg[2]);
//			jtf12.setText(msg[3]);
//			jtf21.setText(msg[4]);
//			jtf22.setText(msg[5]);
//			jtf31.setText(msg[6]);
//			jtf32.setText(msg[7]);
//			jtf41.setText(msg[8]);
//			jtf42.setText(msg[9]);
//			jtf51.setText(msg[10]);
//			jtf52.setText(msg[11]);
//			jtf13.setText(msg[12]);
//			jtf14.setText(msg[13]);
//			jtf23.setText(msg[14]);
//			jtf24.setText(msg[15]);
//			jtf33.setText(msg[16]);
//			jtf34.setText(msg[17]);
//			jtf43.setText(msg[18]);
//			jtf44.setText(msg[19]);
//			jtf53.setText(msg[20]);
//			jtf54.setText(msg[21]);
//			cf.setTime1(Integer.parseInt(msg[22]));
//			cf.setTime2(Integer.parseInt(msg[23]));
//			cf.setTime3(Integer.parseInt(msg[24]));
//			fs.getTime();
//		}
//		}catch(Exception e){
//			IllegalArgumentException illegalargumentexception =new IllegalArgumentException(e.toString());
//			AntiCrack.Fake(illegalargumentexception, e);
//			throw illegalargumentexception;
//		}
//	}
	
	public void read() {
		try{
			IO io = new IO();
			String str = io.read();
			if (null != str) {
				Frame.storage = JSON.parseObject(str, Storage.class);
				cf.setTime1(Frame.storage.getcWinDelay());
				cf.setTime2(Frame.storage.getPressDelay());
				cf.setTime3(Frame.storage.getTabDelay());
			}
			
		}catch(Exception e){
			e.printStackTrace();
			IllegalArgumentException illegalargumentexception =new IllegalArgumentException(e.toString());
			AntiCrack.Fake(illegalargumentexception, e);
			throw illegalargumentexception;
		}
	}
	
	public void effectByCurrentLogic() {
		jtf13.setText(currentLogic.getRole1Logic());
		jtf14.setText(currentLogic.getDog1Logic());
		jtf23.setText(currentLogic.getRole2Logic());
		jtf24.setText(currentLogic.getDog2Logic());
		jtf33.setText(currentLogic.getRole3Logic());
		jtf34.setText(currentLogic.getDog3Logic());
		jtf43.setText(currentLogic.getRole4Logic());
		jtf44.setText(currentLogic.getDog4Logic());
		jtf53.setText(currentLogic.getRole5Logic());
		jtf54.setText(currentLogic.getDog5Logic());
	}

	public void refreashTab(){
		int updateIndex = 0;
		if(currentTab == jbtab1) {
			updateIndex =0;
		}else if(currentTab == jbtab2) {
			updateIndex =1;
		}else if(currentTab == jbtab3) {
			updateIndex =2;
		}else if(currentTab == jbtab4) {
			updateIndex =3;
		}
		FitLogic fitLogic = storage.getLogicList().get(updateIndex);

		fitLogic.setRole1Name(jtf11.getText());
		fitLogic.setRole1Id(jtf12.getText());
		fitLogic.setRole1Logic(jtf13.getText());
		fitLogic.setDog1Logic(jtf14.getText());

		fitLogic.setRole2Name(jtf21.getText());
		fitLogic.setRole2Id(jtf22.getText());
		fitLogic.setRole2Logic(jtf23.getText());
		fitLogic.setDog2Logic(jtf24.getText());

		fitLogic.setRole3Name(jtf31.getText());
		fitLogic.setRole3Id(jtf32.getText());
		fitLogic.setRole3Logic(jtf33.getText());
		fitLogic.setDog3Logic(jtf34.getText());

		fitLogic.setRole4Name(jtf41.getText());
		fitLogic.setRole4Id(jtf42.getText());
		fitLogic.setRole4Logic(jtf43.getText());
		fitLogic.setDog4Logic(jtf44.getText());
		
		fitLogic.setRole5Name(jtf51.getText());
		fitLogic.setRole5Id(jtf52.getText());
		fitLogic.setRole5Logic(jtf53.getText());
		fitLogic.setDog5Logic(jtf54.getText());
		
	}
	
	public void save() {
		refreashTab();
		storage.setcWinDelay(cf.getTime1() == 0?300:cf.getTime1());
		storage.setPressDelay(cf.getTime2() == 0?50:cf.getTime2());
		storage.setTabDelay(cf.getTime3() == 0?3:cf.getTime3());
		new IO().save();
		
	}
	
//	public void save() {
//		try{
//		StringBuffer str = new StringBuffer();
//		str.append(jtf13.getText());
//		str.append("'");
//		str.append(jtf14.getText());
//		str.append("'");
//		str.append(jtf23.getText());
//		str.append("'");
//		str.append(jtf24.getText());
//		str.append("'");
//		str.append(jtf33.getText());
//		str.append("'");
//		str.append(jtf34.getText());
//		str.append("'");
//		str.append(jtf43.getText());
//		str.append("'");
//		str.append(jtf44.getText());
//		str.append("'");
//		str.append(jtf53.getText());
//		str.append("'");
//		str.append(jtf54.getText());
//		str.append("'");
//		str.append(cf.getTime1());
//		str.append("'");
//		str.append(cf.getTime2());
//		str.append("'");
//		str.append(cf.getTime3());
//		IO io = new IO();
//		io.save(cf, win1, win2, win3, win4, win5, str.toString());
//		}catch(Exception e){
//			IllegalArgumentException illegalargumentexception =new IllegalArgumentException(e.toString());
//			AntiCrack.Fake(illegalargumentexception, e);
//			throw illegalargumentexception;
//		}
//	}
//	
	
		
}
